// 学习资源相关类型定义
import type { BaseEntity, User, Tag, FileInfo, Comment, Like, Bookmark, Category } from './index'

// 资源类型枚举
export enum ResourceType {
  DOCUMENT = 'document',
  VIDEO = 'video',
  AUDIO = 'audio',
  IMAGE = 'image',
  LINK = 'link',
  COURSE = 'course',
  EXERCISE = 'exercise',
  OTHER = 'other'
}

// 资源状态枚举
export enum ResourceStatus {
  PENDING = 'pending',
  APPROVED = 'approved',
  REJECTED = 'rejected',
  DRAFT = 'draft',
  ARCHIVED = 'archived'
}

// 资源可见性枚举
export enum ResourceVisibility {
  PUBLIC = 'public',
  PRIVATE = 'private',
  GROUP_ONLY = 'group_only',
  PASSWORD_PROTECTED = 'password_protected'
}

// 学习资源接口
export interface LearningResource extends BaseEntity {
  title: string
  description: string
  type: ResourceType | string
  status: ResourceStatus | string
  visibility: ResourceVisibility | string
  uploaderId: string | number
  uploader?: User
  file?: FileInfo
  url?: string
  duration?: number
  size?: number
  format?: string
  coverImage?: string
  thumbnail?: string
  tags?: Tag[]
  category?: Category
  viewCount: number
  downloadCount: number
  favoriteCount: number
  likeCount: number
  commentCount: number
  shareCount: number
  rating?: number
  ratingCount?: number
  isFeatured?: boolean
  isHot?: boolean
  isRecommended?: boolean
  groupId?: string | number
  password?: string
  allowedUsers?: string[]
  allowedGroups?: string[]
  accessCount?: number
  lastAccessAt?: string
  metadata?: Record<string, any>
  lockStatus?: 'locked' | 'unlocked'
  lockExpiresAt?: string
  comments?: Comment[]
  likes?: Like[]
  bookmarks?: Bookmark[]
}

// 资源搜索参数接口
export interface ResourceSearchParams {
  keyword?: string
  type?: ResourceType | string
  category?: string | number
  status?: ResourceStatus | string
  visibility?: ResourceVisibility | string
  uploaderId?: string | number
  tags?: string[]
  sortBy?: string
  sortOrder?: 'asc' | 'desc'
  page?: number
  pageSize?: number
  startDate?: string
  endDate?: string
  minRating?: number
  maxRating?: number
  minViews?: number
  maxViews?: number
  featured?: boolean
  hot?: boolean
  recommended?: boolean
  groupId?: string | number
  includePrivate?: boolean
}

// 创建资源接口
export interface CreateResource {
  title: string
  description: string
  type: ResourceType | string
  visibility: ResourceVisibility | string
  file?: FileInfo
  url?: string
  coverImage?: string
  tags?: string[]
  categoryId?: string | number
  groupId?: string | number
  password?: string
  allowedUsers?: string[]
  allowedGroups?: string[]
  metadata?: Record<string, any>
}

// 更新资源接口
export interface UpdateResource {
  title?: string
  description?: string
  type?: ResourceType | string
  status?: ResourceStatus | string
  visibility?: ResourceVisibility | string
  file?: FileInfo
  url?: string
  coverImage?: string
  tags?: string[]
  categoryId?: string | number
  groupId?: string | number
  password?: string
  allowedUsers?: string[]
  allowedGroups?: string[]
  metadata?: Record<string, any>
  isFeatured?: boolean
  isHot?: boolean
  isRecommended?: boolean
}

// 资源统计接口
export interface ResourceStats {
  views: number
  downloads: number
  favorites: number
  likes: number
  comments: number
  shares: number
  rating: number
  ratingCount: number
  accessTrend: {
    date: string
    count: number
  }[]
  demographics?: {
    ageGroups: Record<string, number>
    genders: Record<string, number>
    countries: Record<string, number>
  }
}

// 资源收藏接口
export interface ResourceCollection {
  id: string | number
  userId: string | number
  user?: User
  resourceId: string | number
  resource?: LearningResource
  collectionDate: string
  notes?: string
  folderId?: string | number
  folder?: ResourceFolder
  tags?: Tag[]
}

// 资源文件夹接口
export interface ResourceFolder {
  id: string | number
  userId: string | number
  user?: User
  name: string
  description?: string
  parentId?: string | number
  parent?: ResourceFolder
  resourceCount: number
  folderCount: number
  createdAt: string
  updatedAt: string
  isPublic?: boolean
  isShared?: boolean
}

// 资源评估接口
export interface ResourceEvaluation {
  id: string | number
  resourceId: string | number
  resource?: LearningResource
  userId: string | number
  user?: User
  rating: number
  comment?: string
  helpfulCount?: number
  createdAt: string
  updatedAt?: string
}

// 资源访问记录接口
export interface ResourceAccessLog {
  id: string | number
  resourceId: string | number
  resource?: LearningResource
  userId: string | number
  user?: User
  accessTime: string
  duration?: number
  action: 'view' | 'download' | 'share' | 'favorite' | 'comment'
  device?: string
  browser?: string
  ipAddress?: string
  location?: string
}

// 资源推荐接口
export interface ResourceRecommendation {
  id: string | number
  resourceId: string | number
  resource?: LearningResource
  recommendedUserId: string | number
  recommendedByUserId?: string | number
  recommendedByUser?: User
  reason?: string
  score?: number
  isRead?: boolean
  recommendedAt: string
  readAt?: string
}

// 资源共享接口
export interface ResourceShare {
  id: string | number
  resourceId: string | number
  resource?: LearningResource
  sharerId: string | number
  sharer?: User
  receiverId?: string | number
  receiver?: User
  groupId?: string | number
  accessType: 'view' | 'download' | 'edit'
  expiresAt?: string
  shareKey?: string
  isAccepted?: boolean
  sharedAt: string
  acceptedAt?: string
  notificationStatus?: 'pending' | 'sent' | 'delivered' | 'read'
}

// 资源版本接口
export interface ResourceVersion {
  id: string | number
  resourceId: string | number
  resource?: LearningResource
  versionNumber: number
  file?: FileInfo
  modifiedByUserId: string | number
  modifiedByUser?: User
  modificationReason?: string
  createdAt: string
  isActive?: boolean
}

// 资源标签统计接口
export interface ResourceTagStats {
  tagId: string | number
  tagName: string
  resourceCount: number
  viewCount: number
  downloadCount: number
  likeCount: number
  favoriteCount: number
  rating: number
}

// 资源分类统计接口
export interface ResourceCategoryStats {
  categoryId: string | number
  categoryName: string
  resourceCount: number
  viewCount: number
  downloadCount: number
  likeCount: number
  favoriteCount: number
  rating: number
}

// 资源格式统计接口
export interface ResourceFormatStats {
  format: string
  resourceCount: number
  totalSize: number
  viewCount: number
  downloadCount: number
}

// 资源评论接口
export interface ResourceComment extends Comment {
  resourceId: string | number
  resource?: LearningResource
}

// 资源评分接口
export interface ResourceRating {
  id: string | number
  resourceId: string | number
  resource?: LearningResource
  userId: string | number
  user?: User
  rating: number
  createdAt: string
  updatedAt?: string
}

// 资源下载记录接口
export interface ResourceDownload {
  id: string | number
  resourceId: string | number
  resource?: LearningResource
  userId: string | number
  user?: User
  downloadTime: string
  device?: string
  ipAddress?: string
  location?: string
}

// 资源报告接口
export interface ResourceReport {
  id: string | number
  resourceId: string | number
  resource?: LearningResource
  reporterId: string | number
  reporter?: User
  reason: string
  description?: string
  status: 'pending' | 'processing' | 'resolved' | 'dismissed'
  createdAt: string
  resolvedAt?: string
  resolvedByUserId?: string | number
  resolvedByUser?: User
}

// 资源分析接口
export interface ResourceAnalytics {
  resourceId: string | number
  resource?: LearningResource
  totalViews: number
  totalDownloads: number
  totalFavorites: number
  totalLikes: number
  totalComments: number
  totalShares: number
  averageRating: number
  engagementRate: number
  conversionRate: number
  retentionRate: number
  completionRate?: number
  dropOffPoints?: {
    position: number
    percentage: number
  }[]
  userSegments?: {
    name: string
    count: number
    engagement: number
  }[]
  performanceTrend: {
    date: string
    views: number
    downloads: number
    likes: number
    comments: number
  }[]
}